package com.lishe.lishe.lishe.module.myorder.http;

import com.lishe.lishe.lishe.common.Globals;
import com.lishe.lishe.asynchttp.HttpUtils;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.ResponseHandlerInterface;

import java.util.List;


/**
 * Created by lwa on 2017/8/11.
 * 订单网络接口
 */

public class HttpMyOrder {
    //数据所在的表
    private static final String TABLE_ORDER = "order/";
    private static final String TABLE_ORDER1 = "Order1/";
    private static final String TABLE_ORDER2= "Order2/";
    private static final String TABLE_USER = "User/";


    /**
     * 个人中心订单列表接口
     *
     * @param token
     * @param status 订单状态：0、全部订单；1、待付款；2、代发货；3、待收货；4、已完成；5、退款/退货
     * @throws Exception
     */
    public static void getOrderMsg(String token, int status, ResponseHandlerInterface response) throws Exception {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("status", status);
        HttpUtils.post(Globals.LISHE_URL + TABLE_USER + "order/", params, response);
    }

    /**
     * 订单详情-订单收货地址接口
     *
     * @param orderId  订单id
     * @param response 响应器
     */
    public static void getOrderAddress(String token, String orderId, ResponseHandlerInterface response) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("tid", orderId);
        HttpUtils.post(Globals.LISHE_URL + "Home/" + TABLE_ORDER + "receiveGoodsInfo/", params, response);
    }

    /**
     * 取消订单
     *
     * @param paymentId 支付的paymentId
     * @param response  响应器
     */
    public static void cancleOrder(String token, String paymentId, ResponseHandlerInterface response) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("payment_id", paymentId);
        HttpUtils.post(Globals.LISHE_URL + TABLE_ORDER + "cancelOrder/", params, response);
    }

    /**
     * 确认收货
     *
     * @param paymentId 支付的paymentId
     * @param response  响应器
     */
    public static void confirmOrder(String token, String paymentId, ResponseHandlerInterface response) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("payment_id", paymentId);
        HttpUtils.post(Globals.LISHE_URL + TABLE_ORDER + "confirmOrder/", params, response);
    }

    /**
     * 创建订单(购物车 结算 按钮)
     *
     * @param token
     * @param itemList
     */
    public static void createOrder(String token, List<String> itemList, ResponseHandlerInterface response) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("itemList", itemList.toArray());
        HttpUtils.post(Globals.LISHE_URL + TABLE_ORDER2 + "order/", params, response);
    }

    /**
     * 创建订单完成订单生成(购物车 结算 按钮)
     *
     * @param token
     * @param remark     备注
     * @param shopIds    商铺ID
     * @param itemIds    商品ID
     * @param dlytmplIds 配送模板ID，取shop里的template_id字段  (createOrder接口中取到)
     * @param postFees   运费
     * @param skuIds     库存id
     * @param response
     */
    public static void createOrderFinish(String token, List<String> remark, List<String> shopIds, List<String> itemIds,
                                         List<String> dlytmplIds, List<String> postFees, List<String> skuIds,List<String >cartIds,
                                         String couponCode, String totalPrice, ResponseHandlerInterface response) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("remark", remark);
        params.put("shopIds", shopIds);
        params.put("itemIds", itemIds);
        params.put("dlytmplIds", dlytmplIds);
        params.put("postFees", postFees);
        params.put("skuIds", skuIds);
        params.put("cartIds", cartIds);
        params.put("couponCode", couponCode);
        params.put("totalPrice", totalPrice);
        HttpUtils.post(Globals.LISHE_URL + TABLE_ORDER2 + "addUserOrder/", params, response);
    }
}
